﻿if (!window.sps) {
    window.sps = {};
}
;



if (!sps.ui) {
    sps.ui = {};
}
;
sps.ui.mapControl = null;
sps.ui.map = null;
sps.ui.scene = null;

function initUI() {
    Ext.Loader.setConfig({ enabled: true });
    Ext.create("Ext.Viewport", {
        layout: 'border',
        items: [{
            region: 'north',
            id: 'top',
            html: '<div id="header"><div id="siteLogo"></div><div id="siteLogo2"></div></div>'
        }, {
            region: 'west',
            layout: 'accordion',
            items: [{

        }, {

    }],
    width: 180,
    collapsible: true,
    split: true
}, {
    region: 'center',
    id: 'content',
    xtype: 'panel',
    layout: 'border',
    items: [{
        id: 'map_query_panel',
        region: 'south',
        height: 180,
        collapsible: true,
        collapsed: true,
        split: true
    }, {
        id: 'mapPanel',
        region: 'center',
        xtype: 'panel',
        dockedItems: [
                    {
                        xtype: 'toolbar',
                        height: 26,
                        dock: 'top',
                        items: [
                            {
                                id: 'map_tool_fullExtent',
                                xtype: 'button',
                                text: '全图'
                            },
                            {
                                id: 'map_tool_pan',
                                xtype: 'button',
                                text: '平移'
                            },
                            {
                                id: 'map_tool_zoomIn',
                                xtype: 'button',
                                text: '放大'
                            },
                            {
                                id: 'map_tool_zoomOut',
                                xtype: 'button',
                                text: '缩小'
                            },
                            {
                                id: 'map_tool_measureDistance',
                                xtype: 'button',
                                text: '距离'
                            },
                            {
                                id: 'map_tool_measureArea',
                                xtype: 'button',
                                text: '面积'
                            },
                            {
                                id: 'map_tool_tbseparator',
                                xtype: 'tbseparator'
                            },
                            {
                                id: 'map_tool_geoQuery',
                                xtype: 'splitbutton',
                                text: '空间查询',
                                menu: {
                                    xtype: 'menu',
                                    width: 120,
                                    items: [
                                        {
                                            id: 'map_tool_pointQuery',
                                            xtype: 'menuitem',
                                            text: '点查询'
                                        },
                                        {
                                            id: 'map_tool_lineQuery',
                                            xtype: 'menuitem',
                                            text: '线查询'
                                        },
                                        {
                                            id: 'map_tool_regionQuery',
                                            xtype: 'menuitem',
                                            text: '面查询'
                                        }
                                    ]
                                }
                            },
                            {
                                id: 'map_tool_clear',
                                xtype: 'button',
                                text: '清除'
                            }, {
                                id: 'upload-test',
                                xtype: 'button',
                                text: '上传'
                            },
                            '->',
                            {
                                id: 'map_type_vector',
                                xtype: 'button',
                                text: '地图'
                            },
                            {
                                id: 'map_type_glb',
                                xtype: 'button',
                                text: '三维'
                            }
                        ]
                    }
                ],
        html: '<div id="mapContent"><div id="vctMap"></div><div id="glbMap"></div>'
    }]
}]
});
addElementListen();
Ext.MessageBox.wait("正在初始化地图，请稍等...", "提示");
try {
    initMap();
} catch (e) {

} finally {
    Ext.MessageBox.close();
}


}

function initMap() {
    sps.ui.mapControl = new sps.gis.supermap.MapControl();
    sps.ui.map = sps.ui.mapControl.initMap('vctMap');

}

;

function addElementListen() {
    Ext.get('map_type_vector').on('click', function () {
        switchMap('vector');
    });
    Ext.get('map_type_glb').on('click', function () {
        switchMap('glb');
    });
    Ext.get('map_tool_fullExtent').on('click', function () { sps.ui.mapControl.fullExtent(); });
    Ext.get('map_tool_pan').on('click', function () { sps.ui.mapControl.pan(); });
    Ext.get('map_tool_zoomIn').on('click', function () { sps.ui.mapControl.zoomIn(); });
    Ext.get('map_tool_zoomOut').on('click', function () { sps.ui.mapControl.zoomOut(); });
    Ext.get('map_tool_measureDistance').on('click', function () { sps.ui.mapControl.measureDistance(); });
    Ext.get('map_tool_measureArea').on('click', function () { sps.ui.mapControl.measureArea(); });
    Ext.get('upload-test').on('click', function () {

        var win = Ext.create('sps.ui.UploadWindow', { formdata: [{ 'name': 'code', 'caption': '编号', 'value': 20 },
        { 'name': 'name', 'caption': '名称', 'value': '测试值'}]
        });
        win.title = '测试窗体';
        win.show();

    });
    Ext.get('map_tool_clear').on('click', function () { sps.ui.mapControl.clearGraphics(); });
    Ext.get('mapPanel-body').on('resize', function () {
        var mapPanel = Ext.get('mapPanel-body');
        var workLayer = Ext.get('vctMap_workLayer');
        if (workLayer) {
            workLayer.setStyle('width', mapPanel.getStyle('width'));
            workLayer.setStyle('height', mapPanel.getStyle('height'));
        }
    });
}

;

function switchMap(type) {
    var vctMap = Ext.get('vctMap');
    var glbMap = Ext.get('glbMap');
    if (type == 'vector') {
        Ext.get('map_tool_fullExtent').setStyle('display', 'block');
        Ext.get('map_tool_pan').setStyle('display', 'block');
        Ext.get('map_tool_zoomIn').setStyle('display', 'block');
        Ext.get('map_tool_zoomOut').setStyle('display', 'block');
        Ext.get('map_tool_measureDistance').setStyle('display', 'block');
        Ext.get('map_tool_measureArea').setStyle('display', 'block');
        Ext.get('map_tool_tbseparator').setStyle('display', 'block');
        Ext.get('map_tool_geoQuery').setStyle('display', 'block');
        Ext.get('map_tool_clear').setStyle('display', 'block');
        vctMap.setStyle('display', 'block');
        glbMap.setStyle('display', 'none');
    } else if (type == 'glb') {
        if (!sps.ui.scene) {
            sps.ui.scene = sps.ui.mapControl.initScene('glbMap');
        }
        Ext.get('map_tool_fullExtent').setStyle('display', 'none');
        Ext.get('map_tool_pan').setStyle('display', 'none');
        Ext.get('map_tool_zoomIn').setStyle('display', 'none');
        Ext.get('map_tool_zoomOut').setStyle('display', 'none');
        Ext.get('map_tool_measureDistance').setStyle('display', 'none');
        Ext.get('map_tool_measureArea').setStyle('display', 'none');
        Ext.get('map_tool_tbseparator').setStyle('display', 'none');
        Ext.get('map_tool_geoQuery').setStyle('display', 'none');
        Ext.get('map_tool_clear').setStyle('display', 'none');
        vctMap.setStyle('display', 'none');
        glbMap.setStyle('display', 'block');
    }
};

sps.ui.UploadWindow = Ext.define('sps.ui.UploadWindow', {
    extend: 'Ext.window.Window',

    height: 390,
    width: 627,
    layout: {
        type: 'border'
    },
    title: 'My Window',
    formdata: {},

    initComponent: function () {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'panel',
                    region: 'west',
                    width: 187,
                    title: 'My Panel'
                },
                {
                    id: 'eq_form',
                    xtype: 'form',
                    region: 'center',
                    autoScroll: true,
                    bodyPadding: 10,
                    layout: 'column',
                    dockedItems: [
                        {
                            xtype: 'toolbar',
                            dock: 'bottom',
                            items: [
                                '->',
                                {
                                    xtype: 'button',
                                    text: '维护记录'
                                },
                                {
                                    xtype: 'button',
                                    text: '编辑',
                                    handler: function () {
                                        var form = Ext.getCmp('eq_form');
                                        for (var i = 0, len = form.items.items.length; i < len; i++) {
                                            form.items.items[i].setReadOnly(false);
                                        }
                                        form.doLayout();

                                    }
                                },
                                {
                                    xtype: 'button',
                                    text: '提交'
                                },
                                {
                                    xtype: 'button',
                                    text: '取消'
                                },
                                {
                                    xtype: 'button',
                                    text: '关闭',
                                    handler: function () {
                                        me.close();
                                    }
                                }
                            ]
                        }
                    ]
                }
            ]
        });
        me.callParent(arguments);
        me.initForm();

    },

    initForm: function () {
        var form = Ext.getCmp('eq_form');
        for (var j = 0; j < 20; j++) {
            for (var i = 0, len = this.formdata.length; i < len; i++) {
                var field = Ext.create('Ext.form.TextField', { 'padding': 5, 'columnWidth': '.5', 'labelWidth': 60, 'labelAlign': 'right', 'readOnly': true });
                field.name = this.formdata[i].name;
                field.fieldLabel = '名字个数';
                field.setValue(this.formdata[i].value);
                form.items.add(field);
            }
        }
    }
});
